# -*- coding: utf-8 -*-
"""
测试轮子中的accuracy和sklearn中的accuracy
Created on Mon Feb 12 11:16:07 2018

@author: Allen
"""
import numpy as np
from sklearn import datasets

digits = datasets.load_digits()

X = digits["data"]
y = digits["target"]

from playML.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split( X, y )

from playML.knn import KNNClassifier
my_knn = KNNClassifier( k = 3 )
my_knn.fit( X_train, y_train )
y_predict = my_knn.predict( X_test )

from playML.metrics import accuracy_score

accuracy = accuracy_score( y_test, y_predict )

accuracy2 = my_knn.score( X_test, y_test )

'''
    sklearn 中的 accuracy
'''
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split( X, y )

from sklearn.neighbors import KNeighborsClassifier
my_knn_clf = KNeighborsClassifier( n_neighbors = 3 )
my_knn_clf.fit( X_train, y_train )
y_predict = my_knn_clf.predict( X_test )

from sklearn.metrics import accuracy_score 
res = accuracy_score( y_test, y_predict )

res1 = my_knn_clf.score( X_test, y_test )

print( res, res1 ) # 输出0.991111111111 0.991111111111